﻿@using System.Data
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
}

<script src="/Scripts/ajaxfileupload.js"></script>
<script language="javascript" type="text/javascript" src="/Scripts/My97DatePicker/WdatePicker.js"></script>

<style>
    *{overflow: auto;}
     .pjimg{ width: 100%;height: 100px;}
    .pjimg img{ width: 70px;height: 70px;float: left;margin-left: 2px;}
</style>


    <div style="font-size: 12px;margin-top: 10px;">
        @ViewData["Name"]
    </div>
    <div style="font-size: 12px;margin-top: 10px;">
        评价内容
    </div>
    <div>
        <textarea id="content" style="width: 50%;height: 50px; "></textarea>
    </div>
    <div style="font-size: 12px;margin-top: 10px;">
        会员名称
    </div>
    <div>
        <input type="text" id="name" />
    </div>
    <div style="font-size: 12px;margin-top: 10px;">
        购买时间
    </div>
    <div>
        <input type="text" id="time" value="" style="width: 100px;" onclick="WdatePicker()  " />
    </div>
    <div style="font-size: 12px;margin-top: 10px;">
        宝贝快照
    </div>

    <div class="pjimg">
        <img src="/Images/sctp.jpg" onclick="checkfile()" />
        <input id="fileToUpload" style="display: none; cursor: pointer;" type="file" onchange="upload()" name="upfile">

    </div>

    <div>

    </div>
    <div style="font-size: 12px;">
        评价星级
    </div>
    <div class="pjrnk" style="margin-top:10px;">
        <input type="hidden" id="rnk" value="5" />
        <img src="/Images/redx.png" />
        <img src="/Images/redx.png" />
        <img src="/Images/redx.png" />
        <img src="/Images/redx.png" />
        <img src="/Images/redx.png" />
    </div>

    <div style="width: 600px; height: 40px; margin-top: 50px; ">
        <div class="botton" style="margin-left: 50px;" onclick="edit()">保存</div>
        <div class="botton" style="margin-left: 50px;" onclick="history.go(-1)">取消</div>
    </div>


<script>
    var gid = "@ViewData["id"]";
    function edit() {
        var gid = "@ViewData["id"]";
        var content = $("#content").val();
        if (content == "") {
            alert("请输入评价内容！");
            return false;
        }
        var rnk = $("#rnk").val();
        var img = "";
        var name = $("#name").val();
        if (name == "") {
            alert("请输入会员名称！");
            return false;
        }
        if ($(".pjimg img").size() > 1) {
            $(".pjimg img").each(function(i) {
                if (i >= 1) {
                    img += $(this).attr("src") + ",";
                }
            });
            img = img.substring(0, img.length - 1);
        }
        var time = $("#time").val();
        if (time == "") {
            alert("请选择购买时间！");
            return false;
        }
        $.post("@Url.Action("EditPingJian")", { id: 0, gid: gid, rnk: rnk, img: img, content: content, name: name, time: time }, function (row) {
            if (row > 0) {
                alert("感谢您的评价！");
                history.go(-1);
            } else {
                alert("评价失败！");
            }
        });
    }


    $(".pjrnk img").click(function() {
        var j = $(this).index();
        $("#rnk").val(j);

        for (var i=0;i<=j;i++) {
            $(".pjrnk img:eq(" + i + ")").attr("src", "/Images/redx.png");
        }
        for (var i = 5; j<=i; i--) {
            $(".pjrnk img:eq(" + i + ")").attr("src", "/Images/blackx.png");
        }
    });

    function checkfile() {
        if ($(".pjimg img").size() == 4) {
            alert("只能上传三张图片！");
            return false;
        }
        $('#fileToUpload').click();
    }
    function upload() {
        var val = $("#fileToUpload").val();
        if (val == "") {
            alert("请上传文件");
            return false;
        }
        var suffix = val.split('.');
        var arr = new Array("png", "jpg", "gif");
        if (arr.indexOf(suffix[suffix.length - 1]) < 0) {
            alert("上传格式有误！");
        } else {
            $.ajaxFileUpload({
                url: '@Url.Action("UploadImg")',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json',
                success: function (data, status) {
                    var str = "";
                    if (data.status == 1) {
                        $(".pjimg").append("<img src=\"" + data.path + "\"/>");

                    } else {

                    }

                }
            });
        }
    }
</script>